package com.demo.sys.controller;

import com.demo.sys.entity.Student;
import com.demo.sys.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hailang
 * @since 2023-04-11
 */

@RestController
@RequestMapping("/student")
public class StudentController {

    //返回hello
    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }

    //查询所有学生信息接口
    @Autowired
    private StudentMapper studentMapper;

    @GetMapping("/findAll")
    public Object findAll() {
        return studentMapper.selectList(null);
    }

    //根据id查询学生信息接口
    @GetMapping("/findById/{id}")
    public Object findById(@PathVariable("id") Integer id) {
        return studentMapper.selectById(id);
    }


    //添加学生信息接口
    @GetMapping("/add")
    public Object add(Student student) {
        studentMapper.insert(student);
        return "添加成功";
    }

    //通过id修改学生学生的名字，性别，年龄，班级接口
    @GetMapping("/update/{id}")
    public Object update(@PathVariable("id") Integer id, Student student) {
        student.setId(id);
        studentMapper.updateById(student);
        return "修改成功";
    }
    //通过id删除学生信息接口
    @GetMapping("/deleteById/{id}")
    public Object deleteById(@PathVariable("id") Integer id) {
        studentMapper.deleteById(id);
        return "删除成功";
    }


}
